package com.opal.system.controller;

import com.opal.domain.R;
import com.opal.domain.ReturnMessageData;
import com.opal.system.entity.table.OpalPermission;
import com.opal.system.entity.table.OpalRole;
import com.opal.system.service.OpalPermissionService;
import com.opal.system.service.OpalRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/manage")
public class OpalRoleController {

    @Autowired
    private OpalRoleService opalRoleService;

    /**
     * 查询所有角色
     * @return
     */
    @RequestMapping("/role/selectallrole")
    @ResponseBody
    public List<OpalRole> selectAllrole() {
        List<OpalRole> opalPermission= opalRoleService.selectAllrole();
        return opalPermission;
    }

    /**
     * 修改角色信息
     * @param opalRole
     * @param opalRole
     * @return
     */
    @RequestMapping("/role/updateroleInfo")
    @ResponseBody
    public R updateRole(OpalRole opalRole) {
        R rmd=	opalRoleService.updateRoleService(opalRole);
        return rmd;
    }

    /**
     * 给角色分配权限
     * @param permisssIds
     * @param roleId
     * @return
     */
    @RequestMapping("/role/updatePermissionRoleId")
    @ResponseBody
    public Object updatePermissionRoleId(@RequestParam("permisssIds[]")List<Long> permisssIds, Long roleId){
        return   opalRoleService.updatePermissionRoleIdService(permisssIds,roleId);
    }

    /**
     * 添加角色
     * @param opalRole
     * @return
     */
    @RequestMapping("/role/addRole")
    @ResponseBody
    public R addRole(OpalRole opalRole) {
        R rmd=	opalRoleService.addRoleService(opalRole);
        return rmd;
    }

    /**
     * 删除角色
     * @param opalRoles
     * @return 数组权限id
     */
    @RequestMapping("/role/deleteRole")
    @ResponseBody
    public ReturnMessageData deleteRole(@RequestBody OpalRole[] opalRoles) {
        ReturnMessageData roleid=	opalRoleService.deleteRoleService(opalRoles);
        return roleid;
    }

    /**
     * 勾选权限表的数据
     * @param roleId
     * @return
     */
    @RequestMapping("/role/selectPermissionByRoleId")
    @ResponseBody
    public List<OpalPermission> selectPermissionByRoleId(Long roleId){
        return   opalRoleService.selectPermissionByRoleIdservice(roleId);
    }

    /**
     * 查询所有的权限 --刷新easyui的table
     * @return
     */
    @RequestMapping("/role/selectPermission")
    @ResponseBody
    public Object selectPermission(){
        return opalRoleService.selectPermissionService();
    }


}
